home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / mathpas.zip / MATH.QA < prev   
Text File  |  1990-05-30  |  4KB  |  104 lines

  1.  
  2.  
  3. TITLE: NUMERIC PROCESSING IN TURBO PASCAL
  4. ===========================================================
  5.  
  6. TP 4.0 5.0 5.5 - LARGE INTEGER TYPE SUPPORT
  7. Q. Does Turbo Pascal 4.0+ support large integers?
  8. A. Yes.  TP 4.0+ has virtually every incarnation of 8-, 16-, and
  9.    32-bit integers: shortint, integer, longint, byte, and word.
  10.  
  11.  
  12. TP 4.0 5.0 5.5 - FLOATING-POINT PARAMETERS
  13. Q. How are floating-point numbers passed to procedures in
  14.    versions 4.0 and 5.0+?
  15. A. In version 5.0+, the numbers are passed using the CPU stack.
  16.    However, in version 4.0, they are passed via the 80x87
  17.    coprocessor stack.
  18.  
  19. TP 4.0 5.0 5.5 - 80x87 NUMERIC COPROCESSOR
  20. Q. How will the compiler use my 80387 coprocessor?
  21. A. The compiler will treat it as an 8087 coprocessor and none of
  22.    it's extended capabilities will be used.
  23.  
  24. TP 4.0 5.0 5.5 - COMP TYPE USES
  25. Q. What type is Comp? What is it useful for?
  26. A. The Comp type is a cross between an integer and a real
  27.    type and is available when 8087 code is generated {$N+}. If no
  28.    math coprocessor is available, specify {$N+,E+} and the
  29.    emulator will support the Comp type. The compiler treats it as
  30.    a real type without an exponent. Thus Comp is useful when you
  31.    need to store extremely large numbers but don't need a decimal
  32.    point. For example, you might use variables of type Comp to
  33.    store amounts in cents and divide the value of the variable by
  34.    100 to determine what the value in dollars and cents would be.
  35.  
  36. TP 4.0 5.0 5.5 - SIGNIFICANT DIGITS OF 8087 FLOATING-POINT TYPES
  37. Q. How many significant digits do the 8087 floating-point types
  38.    provide?
  39. A.      Type           Digits of precision
  40.        --------       -------------------
  41.        single               7-8
  42.        double              15-16
  43.        extended            19-20
  44.        comp                19-20
  45.  
  46. TP 4.0 5.0 5.5 - INTERMEDIATE RESULTS OF REAL NUMBER EXPRESSIONS
  47. Q. Are the intermediate results of real number expressions
  48.    stored in the 8087 registers?
  49. A. Yes.  In all versions, all intermediate calculations of real
  50.    number expressions are stored on the coprocessor stack.
  51.  
  52. TP 4.0 5.0 5.5 - ROUNDING WITH IEEE FLOATING-POINT
  53. Q. How does rounding work with IEEE floating-point numbers?
  54. A. The 8087 math coprocessor uses a different method for
  55.    rounding numbers than what you may be used to. In order to
  56.    achieve a more even distribution of values, the 8087 uses a
  57.    method sometimes called "Banker's Rounding." This method
  58.    dictates that a number will always be rounded to the nearest
  59.    EVEN number. Note that this is quite different than always
  60.    rounding UP. Here are a couple of examples: 
  61.    
  62.      Round(0.5) = 0
  63.      Round(1.5) = 2
  64.  
  65.  
  66. TP 4.0 5.0 5.5 RANDOM RANDOMIZE - RANDOM NUMBER GENERATOR FORMULA
  67. Q. What is the formula used by the random number generator in
  68.    Turbo Pascal?
  69. A. The random number generator in Turbo Pascal uses 32-bit
  70.    arithmetic.  It maintains a 32-bit 'seed', which is treated as
  71.    an unsigned integer.  Each call to Random changes the seed by
  72.    the formula seed:=multiplier * seed + 1 mod 4294967296 Turbo
  73.    Pascal uses the multiplier, 134775813.  The modulus,
  74.    4294967296, is 2 to the power 32.  The multiplier was chosen
  75.    carefully for its nice randomness properties.  The seed will
  76.    take on every 32-bit integer before repeating.
  77.  
  78.  
  79. TP 4.0 5.0 5.5 TRUNC - CONVERTING REAL NUMBERS INTO INTEGERS
  80. Q. How do you convert real numbers into integers?
  81. A. Use the Round or Trunc function and assign the result to an
  82.    integer:
  83.  
  84.         var i : integer;
  85.         begin
  86.           i := round(12.43); i := trunc(22.22);
  87.         end.
  88.  
  89.  
  90. TP 5.0 5.5 - TAKING ADVANTAGE OF IEEE FLOATING-POINT TYPES
  91. Q. What is the best approach to taking advantage of the new IEEE
  92.    floating-point types?
  93. A. The new IEEE floating-point types are available when you
  94.    compile your program with {$N+} and you have a math
  95.    coprocessor; they are also available if you don't have a
  96.    coprocessor, but specify {N+,E+}. The 8087 emulator has
  97.    greater precision, but is significantly slower than the fast,
  98.    6-byte, software-only reals. When developing programs that
  99.    will be compiled and run on machines without the 8087
  100.    coprocessor, consider the tradeoffs of speed (built-in reals)
  101.    vs. precision (8087 hardware/emulation) and make the
  102.    appropriate choice.
  103.  
  104.